<?php
/*
 * program:	均源
 * author:	雨中漫步 & 上善若水 & qhxin
 * email:	qhxin@qhxin.com
 * date:	2014/11/11
 * description:	又是一年双十一，不能剁手，就写点东西吧~~~~~~
 */

defined('IN_SCHOOL') or die();

/*{TranslateTagBegin}*/
class control_manage extends base_control{

	//hook ctr_manage_before.php

	public function __construct() {
	
		//hook ctr_manage_parent_init_before.php
		parent::__construct();
		
		//hook ctr_manage_parent_init_after.php
	}
	
	public function do_digest() {
		$tid = abs(intval(core::gpc('tid','G')));
		
		if(empty($tid)) $this->message('tid参数错误','index.php');
		//hook ctr_manage_digest_show_before.php
		$t = $this->talks->talks_show($tid);
		if(empty($t)) $this->message('找不到帖子','index.php');
		
		$fid = $t['fid'];
		
		//hook ctr_manage_digest_before_bbs_get.php
		$bbs = $this->forum->forum_get($fid);
		if(empty($bbs)) $this->message('版块错误','index.php');
		
		$bbs['master'] = array_filter(explode(',', $bbs['master']));
		$bbs['master'][] = 1;
		//hook ctr_manage_digest_after_master_init.php
		
		$core_arr = $this->user->user_core();
		if(!in_array($core_arr['uid'], $bbs['master']))
			$this->message('权限不足', 'index.php');
		
		//hook ctr_manage_digest_edit_before.php
		if($this->talks->talks_edit_digest($tid)) {
			//hook ctr_manage_digest_in_edit.php
			$this->message('修改精华成功', "index.php?index-talk-tid-$tid.htm");
		}
			$this->message('修改精华失败', "index.php?index-talk-tid-$tid.htm");
	}
	
	public function do_allstick() {
		$tid = abs(intval(core::gpc('tid','G')));
		
		if(empty($tid)) $this->message('tid参数错误','index.php');
		//hook ctr_manage_allstick_show_before.php
		$t = $this->talks->talks_show($tid);
		if(empty($t)) $this->message('找不到帖子','index.php');
		
		$fid = $t['fid'];
		
		//hook ctr_manage_allstick_before_bbs_get.php
		$bbs = $this->forum->forum_get($fid);
		if(empty($bbs)) $this->message('版块错误','index.php');
		
		$bbs['master'] = array_filter(explode(',', $bbs['master']));
		$bbs['master'][] = 1;
		//hook ctr_manage_allstick_after_master_init.php
		
		$core_arr = $this->user->user_core();
		if(!in_array($core_arr['uid'], $bbs['master']))
			$this->message('权限不足', 'index.php');
		
		//hook ctr_manage_allstick_edit_before.php
		if($this->talks->talks_edit_allstick($tid)) {
			//hook ctr_manage_allstick_in_edit.php
			$this->message('修改全站置顶成功', "index.php?index-talk-tid-$tid.htm");
		}
			$this->message('修改全站置顶失败', "index.php?index-talk-tid-$tid.htm");
	}
	
	public function do_stick() {
		$tid = abs(intval(core::gpc('tid','G')));
		
		if(empty($tid)) $this->message('tid参数错误','index.php');
		//hook ctr_manage_stick_show_before.php
		$t = $this->talks->talks_show($tid);
		if(empty($t)) $this->message('找不到帖子','index.php');
		
		$fid = $t['fid'];
		
		//hook ctr_manage_stick_before_bbs_get.php
		$bbs = $this->forum->forum_get($fid);
		if(empty($bbs)) $this->message('版块错误','index.php');
		
		$bbs['master'] = array_filter(explode(',', $bbs['master']));
		$bbs['master'][] = 1;
		//hook ctr_manage_stick_after_master_init.php
		
		$core_arr = $this->user->user_core();
		if(!in_array($core_arr['uid'], $bbs['master']))
			$this->message('权限不足', 'index.php');
		
		//hook ctr_manage_stick_edit_before.php
		if($this->talks->talks_edit_stick($tid)) {
			//hook ctr_manage_stick_in_edit.php
			$this->message('修改版块置顶成功', "index.php?index-talk-tid-$tid.htm");
		}
			$this->message('修改版块置顶失败', "index.php?index-talk-tid-$tid.htm");
	}
	
	public function do_retalk() {
		$tid = abs(intval(core::gpc('tid','G')));
		$tfid = abs(intval(core::gpc('tfid','P')));
		
		if(empty($tid)) $this->message('tid参数错误','index.php');
		//hook ctr_manage_retalk_show_before.php
		$t = $this->talks->talks_show($tid);
		if(empty($t)) $this->message('找不到帖子','index.php');
		
		$fid = $t['fid'];
		$tfid = empty($tfid) ? 0:$tfid;
		
		//hook ctr_manage_retalk_before_bbs_get.php
		$bbs = $this->forum->forum_get($fid);
		if(empty($bbs)) $this->message('版块错误','index.php');
		
		$bbs['master'] = array_filter(explode(',', $bbs['master']));
		$bbs['master'][] = 1;
		//hook ctr_manage_retalk_after_master_init.php
		
		$core_arr = $this->user->user_core();
		if(!in_array($core_arr['uid'], $bbs['master']))
			$this->message('权限不足', 'index.php');
		
		//hook ctr_manage_retalk_edit_before.php
		if($this->talks->talks_edit($tid , $tfid)) {
			$this->forum->forum_edit_tj($fid , '-1');
			$this->forum->forum_edit_tj($tfid , '+1');
			//hook ctr_manage_retalk_in_edit.php
			$this->message('移动成功', "index.php?index-forum-fid-$fid.htm");
		}
			$this->message('移动失败', "index.php?index-forum-fid-$fid.htm");
	}
	
	public function do_deltalk() {
		//hook ctr_manage_deltalk_start.php
		if(!$this->is_gid100()) $this->message('权限不足','index.php');
		$tid = abs(intval(core::gpc('tid','G')));
		if(empty($tid)) $this->message('参数错误','index.php');
		
		//hook ctr_manage_deltalk_show_before.php
		$t = $this->talks->talks_show($tid);
		if(empty($t)) $this->message('找不到帖子','index.php');
		
		//删除附件
		//hook ctr_manage_deltalk_del_attach_image_before.php
		$attaches = $this->parse->parse_all_image_md5($t['content']);
		foreach($attaches as $k=>$v) {
			$this->attach->attach_del($v);
		}
		//hook ctr_manage_deltalk_del_attach_files_before.php
		$attaches = $this->parse->parse_all_files_md5($t['content']);
		foreach($attaches as $k=>$v) {
			$this->attach->attach_del($v);
		}
		//删除回帖
		//hook ctr_manage_deltalk_del_comm_before.php
		$this->comm->comm_del($tid);
		//删除层回帖
		//hook ctr_manage_deltalk_del_subrpl_before.php
		$this->subrpl->subrpl_del($tid);
		
		//hook ctr_manage_deltalk_del_talk_before.php
		if($this->talks->talks_delete($tid) ) {
			//hook ctr_manage_deltalk_del_talk_in.php
			$this->forum->forum_edit_tj(0 , '-1');
			//author
			$author = $this->user->get_user_by_uid($t['uid'], false);
			$num = 6;
			//hook ctr_manage_deltalk_before_core_edit.php
			if(!empty($author) && $author['core'] > $num) {
				$this->user->user_core_edit('-', $num, $t['uid'], $author['core']);
			}
			$this->message('删除成功', "index.php?index-forum-fid-0.htm");
		}
			$this->message('删除失败', "index.php?index-forum-fid-0.htm");
	}
	
	public function do_pb() {
		$cid = abs(intval(core::gpc('cid','G')));
		if(empty($cid)) $this->message('cid参数错误','index.php');
		//hook ctr_manage_pb_show_before.php
		$comm = $this->comm->comm_get($cid);
		if(empty($comm)) $this->message('找不到回帖','index.php');
		
		$t = $this->talks->talks_show($comm['fid']);
		if(empty($t)) $this->message('找不到帖子','index.php');
		
		$fid = $t['fid'];
		
		//hook ctr_manage_pb_before_bbs_get.php
		$bbs = $this->forum->forum_get($fid);
		if(empty($bbs)) $this->message('版块错误','index.php');
		
		$bbs['master'] = array_filter(explode(',', $bbs['master']));
		$bbs['master'][] = 1;
		//hook ctr_manage_pb_after_master_init.php
		
		$core_arr = $this->user->user_core();
		if(!in_array($core_arr['uid'], $bbs['master']))
			$this->message('权限不足', 'index.php');
		
		$lc = 0;
		$del_comm = $this->comm->comm_del_one($cid);
		$del_comm = $del_comm && $this->subrpl->subrpl_del_by_fid($cid);
		$del_comm = $del_comm && $this->talks->talks_edit_tj($comm['fid'] ,'-',$lc);
		if($del_comm) {
			//author
			$author = $this->user->get_user_by_uid($comm['uid'], false);
			$num = 2;
			//hook ctr_manage_pb_before_core_edit.php
			if(!empty($author) && $author['core'] > $num) {
				$this->user->user_core_edit('-', $num, $comm['uid'], $author['core']);
			}
			$this->message('屏蔽成功', 'index.php?index-talk-tid-'.$comm['fid'].'.htm');
		}
			$this->message('屏蔽失败', 'index.php?index-talk-tid-'.$comm['fid'].'.htm');
	}
	
	public function do_pbspl() {
		$rid = abs(intval(core::gpc('rid','G')));
		if(empty($rid)) $this->message('rid参数错误','index.php');
		//hook ctr_manage_pbspl_show_before.php
		$subrpl = $this->subrpl->subrpl_get($rid);
		if(empty($subrpl)) $this->message('找不到回帖','index.php');
		
		$t = $this->talks->talks_show($subrpl['ffid']);
		if(empty($t)) $this->message('找不到帖子','index.php');
		
		$fid = $t['fid'];
		
		//hook ctr_manage_pbspl_before_bbs_get.php
		$bbs = $this->forum->forum_get($fid);
		if(empty($bbs)) $this->message('版块错误','index.php');
		
		$bbs['master'] = array_filter(explode(',', $bbs['master']));
		$bbs['master'][] = 1;
		//hook ctr_manage_pbspl_after_master_init.php
		
		$core_arr = $this->user->user_core();
		if(!in_array($core_arr['uid'], $bbs['master']))
			$this->message('权限不足', 'index.php');
		
		$tid = 0;
		$del_srpl = $this->subrpl->subrpl_del_one($rid);
		$del_srpl = $del_srpl && $this->comm->comm_edit_tj($subrpl['fid'] , '-',$tid);
		if($del_srpl) {
			//author
			$author = $this->user->get_user_by_uid($subrpl['uid'], false);
			$num = 2;
			//hook ctr_manage_pbspl_before_core_edit.php
			if(!empty($author) && $author['core'] > $num) {
				$this->user->user_core_edit('-', $num, $subrpl['uid'], $author['core']);
			}
			$this->message('屏蔽成功', 'index.php?simpost-subreply-fid-'.$subrpl['fid'].'.htm');
		}
			$this->message('屏蔽失败', 'index.php?simpost-subreply-fid-'.$subrpl['fid'].'.htm');
	}
	
	//==================>private
	private function is_gid100() {
		$gid = $this->user->user_groupid();
		//hook ctr_manage_in_is_gid100.php
		if($gid == 100){
			return true;
		}
		return false;
	}

	//hook ctr_manage_end.php
}
/*{TranslateTagEnd}*/

?>